cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project(recipe-04 LANGUAGES CXX)

set(CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(CXX_EXTENSIONS OFF)

option(USE_LIBRARY "Compile sources into a library" OFF)

message(STATUS "Compile sources into a library ? ${USE_LIBRARY}")

set(BUILD_SHARED_LIBS OFF)

list(APPEND _source Message.hpp Message.cpp)

# test
include(CMakeDependentOption)
cmake_dependent_option(
    MAKE_STATIC_LIBRARY "Compile sources into a static library" OFF
    USE_LIBRARY ON
)

message(STATUS "Compile sources into a static library ? ${MAKE_STATIC_LIBRARY}")

if(USE_LIBRARY)
    #add_library will create a static library
    #since BUILD_SHARED_LIBS is OFF
    add_library(message ${_source})
    add_executable(hello-world hello-world.cpp)
    target_link_libraries(hello-world message)
else()
    add_executable(hello-world hello-world.cpp ${_source})
endif()